package com.markyao.aop;

import com.markyao.recos.regist.RecosRegistConfig;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j(topic = "m.RecosBroadcastAspect")
@Component
@Aspect
public class RecosBroadcastAspect {


    @Autowired
    RecosRegistConfig recosRegistConfig;

    @Pointcut("within(com.markyao.service.raft.BroadcastConfigInfoService) || within(com.markyao.service.raft.BroadcastRegistService)")
    public void pj(){}

    @Around("pj()")
    public Object aroundBroadcast(ProceedingJoinPoint pjp) throws Throwable{
        if (recosRegistConfig.isGroup() && recosRegistConfig.isLeader()){
            log.info("广播客户端信息.");
            return pjp.proceed();
        }
        return false;
    }

}
